<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="header">
          <el-form
            ref="jylsform"
            :rules="rules"
            :model="jylsform"
            label-width="100px"
            class="flex"
          >
            <el-form-item label="业务编号">
              <el-input v-model="codes" placeholder="请输入编号,多个逗号隔开" />
            </el-form-item>
            <el-form-item label="创建时间" prop="Time">
              <el-date-picker
                v-model="jylsform.Time"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="jylstime"
              />
            </el-form-item>
            <el-form-item label="所属网点" prop="networkNameId">
              <el-select
                v-model="jylsform.networkNameId"
                placeholder="请选择网点"
                style="width: 286px"
              >
                <el-option
                  v-for="(item, index) in jylsnetworkList"
                  :key="index"
                  :label="item.networkName"
                  :value="item.networkName"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button class="cx" @click="jylscx">查询</el-button>
              <elbutton :obj="jylsform" @dj="jylscz" />
            </el-form-item>
            <el-form-item label="账户类型">
              <el-select
                v-model="jylsform.accountType"
                placeholder="请选择账户类型"
                style="width: 286px"
              >
                <el-option
                  v-for="(item, index) in zhtype"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>

            <el-form-item label="账户名称">
              <el-input v-model="jylsform.accountName" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="结算科目">
              <el-cascader
                :options="jylskmlist"
                :show-all-levels="false"
                :props="props"
                @change="kmchange"
              />
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" justify="space-between">
      <el-col :span="6">
        <div class="page">
          当前页共<span>{{ jylstableData.length }}</span
          >项
        </div>
      </el-col>
      <el-col :span="2">
        <div>
          <el-button class="cx">查询</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" justify="space-between">
      <el-col :span="24">
        <elltable
          :loading="jylsloading"
          :data="jylstableData"
          :th="jylsth"
          :n="3"
        />
      </el-col>
    </el-row>
    <div class="block" style="display: flex; justify-content: flex-end">
      <pagination
        :current-page="jylsform.pageDate.pageNum"
        :page-size="jylsform.pageDate.pageSize"
        :total="jylstotal"
        @size-change="jylshandleSizeChange"
        @current-change="jylshandleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import { getOutletsList } from '@/api/dashboard'
import { Getjylstable, Getshowkulist } from '@/api/site'
export default {
  props: {
    zhtype: Array,
    rules: Object

  },
  data() {
    return {
      jylsloading: false,
      jylskmlist: [],
      jylsnetworkList: [],
      // 交易流水查询
      jylsform: {
        accountName: '',
        accountType: 0,
        codes: [],
        endTime: '',
        networkNameId: '辽宁盘锦公司',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        settleSubjectId: '',
        startTime: ''
      },
      jylstableData: [],
      jylstotal: 0,
      jylsth: [],
      props: {
        label: 'title',
        children: 'networkSettleSubjects',
        value: 'title'
      }
    }
  },
  computed: {
    codes: {
      get() {
        return this.jylsform.codes.join(',')
      },
      set(value) {
        this.jylsform.codes = value !== '' ? value.split(',').map(item => item.trim()) : []
      }
    }
  },
  async created() {
    this.getOutLet()
    const res = await Getshowkulist()
    console.log(res)
    this.jylskmlist = res.data
  },
  methods: {
    kmchange(val) {
      this.jylsform.settleSubjectId = val[1]
    },
    // 获取网点列表
    getOutLet() {
      getOutletsList().then((res) => {
        if (res.code === 200) {
          this.jylsnetworkList = res.data
        }
      })
    },
    // 获取时间
    jylstime(value) {
      if (value != null) {
        this.jylsform.startTime = value[0]
        this.jylsform.endTime = value[1]
      } else {
        this.jylsform.startTime = ''
        this.jylsform.endTime = ''
      }
    },
    // handleClick(tab, event) {
    //   console.log(tab, event)
    // },
    async jylscx() {
      this.$refs.jylsform.validate(async valid => {
        if (valid) {
          this.jylsloading = true
          const res = await Getjylstable(this.jylsform)
          this.jylsloading = false
          if (res.code === 200) {
            this.jylstableData = res.data.list.data
            this.jylstotal = res.data.list.total
            this.jylsth = res.data.fields
          } else {
            this.jylstableData = []
            this.jylstotal = 0
          }
        } else {
          return false
        }
      })
    },
    jylshandleSizeChange(val) {
      this.jylsform.pageDate.pageSize = val
      this.jylsform.pageDate.pageNum = 1
      this.jylscx()
    },
    jylshandleCurrentChange(val) {
      this.jylsform.pageDate.pageNum = val
      this.jylscx()
    },
    // 重置
    jylscz(aaa) {
      this.jylsform = aaa
    }
  }
}
</script>
<style lang="scss" scoped>
@import url('../css/css.css');
</style>
